package com.cscj.android.repository.db.dao

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import com.cscj.android.repository.db.entity.HotSearchEntity
import kotlinx.coroutines.flow.Flow

@Dao
interface HotSearchDao {

    @Query("delete from hot_search where sourceType = :sourceType")
    suspend fun deleteByType(sourceType: Int)

    @Insert(onConflict = OnConflictStrategy.IGNORE)
    suspend fun batchInsert(hotSearchList: List<HotSearchEntity>)

    @Query("select * from hot_search where sourceType = :sourceType order by `order`")
    fun getHotSearchList(sourceType: Int): Flow<List<HotSearchEntity>>


    @Query("""
        select * from (select * from hot_search where sourceType = 4 limit :limit)
        union all
        select * from (select * from hot_search where sourceType = 5 limit :limit)
        union all
        select * from (select * from hot_search where sourceType = 1 limit :limit)
        
    """)
    fun getSearchRecommend(limit: Int): Flow<List<HotSearchEntity>>


}